import requests
from base.config.service_config import ServicePort


class ServiceClient:
    def __init__(self, service_name):
        self.service_name = service_name

    @property
    def domain_name(self):
        return "http://127.0.0.1"
    
    @property
    def port(self):
        return getattr(ServicePort, self.service_name)
    
    def build_url(self, url):
        url = f"{self.domain_name}:{self.port}/{self.service_name}{url}"
        return url
    
    def get(self, url, **kwargs):
        return requests.get(self.build_url, **kwargs)

    def post(self, url, **kwargs):
        return requests.post(self.build_url(url), **kwargs)
